<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-row>
<!--        <el-col :span="5">-->
<!--          <el-form-item label="用户id" prop="userid">-->
<!--            <el-input-->
<!--              v-model="queryParams.userid"-->
<!--              placeholder="请输入用户id"-->
<!--              clearable-->
<!--              style="width: 150px;"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->
        <el-col :span="5">
          <el-form-item label="用户名称" prop="username">
            <el-input
              v-model="queryParams.username"
              placeholder="请输入用户名称"
              clearable
              style="width: 150px;"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="定位地点" prop="locationPos">
            <el-input
              v-model="queryParams.locationPos"
              placeholder="请输入定位地点"
              clearable
              style="width: 150px;"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
<!--        <el-col :span="5">-->
<!--          <el-form-item label="定位依据" prop="locationBasis">-->
<!--            <el-input-->
<!--              v-model="queryParams.locationBasis"-->
<!--              placeholder="请输入定位依据"-->
<!--              clearable-->
<!--              style="width: 150px;"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->
        <el-col :span="5">
          <el-form-item label="泄露地点" prop="locationLeak">
            <el-input
              v-model="queryParams.locationLeak"
              placeholder="请输入泄露地点"
              clearable
              style="width: 150px;"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
<!--        <el-col :span="4">-->
<!--          <el-form-item label="定位经度" prop="locationLat">-->
<!--            <el-input-->
<!--              v-model="queryParams.locationLat"-->
<!--              placeholder="请输入定位经度"-->
<!--              clearable-->
<!--              style="width: 150px;"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->

      </el-row>


      <!-- <el-row> -->
<!--        <el-col :span="5">-->
<!--          <el-form-item label="泄露地点" prop="locationLeak">-->
<!--            <el-input-->
<!--              v-model="queryParams.locationLeak"-->
<!--              placeholder="请输入泄露地点"-->
<!--              clearable-->
<!--              style="width: 150px;"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col :span="5">-->
<!--          <el-form-item label="定位纬度" prop="locationLon">-->
<!--            <el-input-->
<!--              v-model="queryParams.locationLon"-->
<!--              placeholder="请输入定位纬度"-->
<!--              clearable-->
<!--              style="width: 150px;"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col :span="5">-->
<!--          <el-form-item label="泄露地所在省" prop="province">-->
<!--            <el-input-->
<!--              v-model="queryParams.province"-->
<!--              placeholder="请输入泄露地点所在省"-->
<!--              clearable-->
<!--              style="width: 150px;"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col :span="5">-->

<!--          <el-form-item label="泄露地所在省" prop="city">-->
<!--            <el-input-->
<!--              v-model="queryParams.city"-->
<!--              placeholder="请输入泄露地所在省"-->
<!--              clearable-->
<!--              style="width: 150px;"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->

      <!-- </el-row> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          plain-->
      <!--          icon="el-icon-plus"-->
      <!--          size="mini"-->
      <!--          @click="handleAdd"-->
      <!--          v-hasPermi="['system:warn:add']"-->
      <!--        >新增-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="success"-->
      <!--          plain-->
      <!--          icon="el-icon-edit"-->
      <!--          size="mini"-->
      <!--          :disabled="single"-->
      <!--          @click="handleUpdate"-->
      <!--          v-hasPermi="['system:warn:edit']"-->
      <!--        >修改-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:warn:remove']"
        >批量删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:warn:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
            <el-button class="inBtn" type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-col>
    </el-row>

    <div style="display: flex">
      <el-card style="flex: 1;padding: 0;">
        <el-table max-height="560" v-loading="loading" :data="warnList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
<!--          <el-table-column label="主键" align="center" prop="id"/>-->
<!--          <el-table-column label="用户id" align="center" prop="userid"/>-->
          <el-table-column label="用户名称" align="center" prop="username"/>
          <el-table-column label="定位地点" align="center" prop="locationPos"/>
          <el-table-column label="定位依据" align="center" prop="locationBasis"/>
          <el-table-column label="定位经度" align="center" prop="locationLat"/>
          <el-table-column label="定位纬度" align="center" prop="locationLon"/>
          <el-table-column label="泄露地点" align="center" prop="locationLeak"/>
          <!-- <el-table-column label="泄露地所在省" align="center" prop="province"/>
          <el-table-column label="泄露地所在省" align="center" prop="city"/> -->
          <el-table-column width="250" label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
<!--              <el-button-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-edit"-->
<!--                @click="handleUpdate(scope.row)"-->
<!--                v-hasPermi="['system:warn:edit']"-->
<!--              >修改-->
<!--              </el-button>-->
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleRouter(scope.row)"
                v-hasPermi="['system:warn:edit']"
              >查看
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:warn:remove']"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>

      </el-card>
      <div style="width: 360px;display: flex;flex-direction:column">
        <div style="flex: 1;">
          <el-card style="height: 100%;">
            <div class="chart-title"><span></span>泄露风险类型统计</div>
            <provinces></provinces>
          </el-card>
        </div>
        <div style="flex: 1;">
          <el-card style="height: 100%;">
            <div class="chart-title"><span></span>泄露风险地区统计</div>
            <areaDom></areaDom>
          </el-card>
        </div>
      </div>
    </div>


    <!-- 添加或修改告警信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form inline ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="用户id" prop="userid">
          <el-input v-model="form.userid" placeholder="请输入用户id"/>
        </el-form-item>
        <el-form-item label="用户名称" prop="username">
          <el-input v-model="form.username" placeholder="请输入用户名称"/>
        </el-form-item>
        <el-form-item label="定位地点" prop="locationPos">
          <el-input v-model="form.locationPos" placeholder="请输入定位地点"/>
        </el-form-item>
        <el-form-item label="定位依据" prop="locationBasis">
          <el-input v-model="form.locationBasis" placeholder="请输入定位依据"/>
        </el-form-item>
        <el-form-item label="定位经度" prop="locationLat">
          <el-input v-model="form.locationLat" placeholder="请输入定位经度"/>
        </el-form-item>
        <el-form-item label="定位纬度" prop="locationLon">
          <el-input v-model="form.locationLon" placeholder="请输入定位纬度"/>
        </el-form-item>
        <el-form-item label="泄露地点" prop="locationLeak">
          <el-input v-model="form.locationLeak" placeholder="请输入泄露地点"/>
        </el-form-item>
        <el-form-item label="泄露地所在省" prop="province">
          <el-input v-model="form.province" placeholder="请输入泄露地点所在省"/>
        </el-form-item>
        <el-form-item label="泄露地所在省" prop="city">
          <el-input v-model="form.city" placeholder="请输入泄露地点所在省"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listWarn, delWarn, updateWarn} from "@/api/combatUser/alarmInformation";
import areaDom from './components/echarts/area.vue';
import provinces from './components/echarts/provinces.vue';

export default {
  name: "Warn",
  components: {areaDom, provinces},
  data() {
    return {
      userId: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 告警信息表格数据
      warnList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // warnState: 0,
        userid: null,
        username: null,
        locationPos: null,
        locationBasis: null,
        locationLat: null,
        locationLon: null,
        locationLeak: null,
        province: null,
        city: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    const userId = this.$route.query.userId;
    if (userId) {
      this.queryParams.userid = userId;
    }
    //
    this.getList();
  },
  methods: {
    /** 查询告警信息列表 */
    getList() {
      this.loading = true;
      listWarn(this.queryParams).then(response => {
        this.warnList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userid: null,
        username: null,
        locationPos: null,
        locationBasis: null,
        locationLat: null,
        locationLon: null,
        locationLeak: null,
        province: null,
        city: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加告警信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      // getWarn(id).then(response => {
      this.form = row;
      this.open = true;
      this.title = "修改告警信息";
      // });
    },
    /**路由跳转详情页*/
    handleRouter(row) {
      this.$router.push('/userPositioningScreen/details?id=' + row.id+'&userid='+row.userid)
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWarn(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
          // else {
          //   addWarn(this.form).then(response => {
          //     this.$modal.msgSuccess("新增成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除告警信息编号为"' + ids + '"的数据项？').then(function () {
        return delWarn(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('userlocation/warn/export', {
        ...this.queryParams
      }, `warn_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.inBtn {
  color: white;
  width: 106px;
  background: linear-gradient(270deg, #2DBFFD 0%, #0E5FFF 100%);
  border-radius: 4px 4px 4px 4px;
}

::v-deep .el-pager li.active {
  background: linear-gradient(270deg, #2DBFFD 0%, #0E5FFF 100%) !important;
}

::v-deep .pagination-container {
  position: unset !important;
}
::v-deep .pagination-container .el-pagination {
  text-align: right;
  margin-right: 0;
}

.inBtn {
  color: white;
  width: 106px;
  background: linear-gradient(270deg, #2dbffd 0%, #0e5fff 100%);
  border-radius: 4px 4px 4px 4px;
}

::v-deep .el-pager li.active {
  background: linear-gradient(270deg, #2dbffd 0%, #0e5fff 100%) !important;
}

::v-deep .el-table {
    min-height: 65vh;
}
.chart-title{
  font-size: 18px;
  font-weight: bold;
  display: flex;
  span{
    display: inline-block;
    width: 5px;
    background-color: red;
    margin-right: 5px;
  }
}
</style>
